package com.huyn.baseframework.utils;

import android.annotation.SuppressLint;

public class PlayerUtil {
	
	public final static int INVALID = -1;

	public static int getInt(String str){
		int num = INVALID;
		
		try {
			num = Integer.parseInt(str);
		} catch (NumberFormatException e) {
			
		}
		
		return num;
	}
	
	public static long getLong(String str){
		long num = 0l;
		
		try {
			num = Long.parseLong(str);
		} catch (NumberFormatException e) {
		}
		
		return num;
	}
	
	@SuppressLint("DefaultLocale")
	public static String byteToM(long num){
		double m = (double) num / 1024 / 1024;
		return String.format("%.2f", m);
	}
	
	public static String millsecondsToStr(int seconds){
		seconds = seconds / 1000;
		String result = "";
		int hour = 0, min = 0, second = 0;
		hour = seconds / 3600;
		min = (seconds - hour * 3600) / 60;
		second = seconds - hour * 3600 - min * 60;
		if (hour < 10) {
			result += "0" + hour + ":";
		} else {
			result += hour + ":";
		}
		if (min < 10) {
			result += "0" + min + ":";
		} else {
			result += min + ":";
		}
		if (second < 10) {
			result += "0" + second;
		} else {
			result += second;
		}
		return result;
	}
	
	public static String millsecondsToMinutes(long t){
//		String s = "";
//		if(0 <= (t /1000 / 60) && (t /1000 / 60) < 10){
//			s = "0" + (t /1000 / 60) + ":";
//		}else{
//			s = (t /1000 / 60) + ":";
//		}
//
//		if(0 <= (t /1000 % 60) && (t /1000 % 60) < 10){
//			s = s + "0" + (t /1000 % 60);
//		}else{
//			s = s + (t /1000 % 60);
//		}
//		return s;
		return millsecondsToFormatMinutes(t);
	}

	public static String millsecondsToFormatMinutes(long t){
		long seconds = t/1000%60;
		long minutes = t/1000/60%60;
		long hours = t/1000/60/60;

		StringBuffer sb = new StringBuffer();
		if(hours > 0) {
			if(hours < 10)
				sb.append("0");
			sb.append(hours).append(":");
		}

		if(minutes < 10)
			sb.append("0");
		sb.append(minutes).append(":");

		if(seconds < 10)
			sb.append("0");
		sb.append(seconds);

		return sb.toString();
	}

}
